DevForce Help Reference
EntityListManager<T> Constructor(EntityManager,Predicate<T>,EntityProperty[])
Example 


EntityManager holding the Entities
A predicate returning true if the tested entity belongs in the list
The watched properties. If supplied, changes to values in the watched properties trigger filtering. If null, any changes to Entities of this type will trigger filtering.
Initialize a new instance of the EntityListManager.
Syntax
'Declaration
 
Public Function New( _
   ByVal entityManager As EntityManager, _
   ByVal filter As Predicate(Of T), _
   ByVal filterProperties() As EntityProperty _
)
'Usage
 
Dim entityManager As EntityManager
Dim filter As Predicate(Of T)
Dim filterProperties() As EntityProperty
 
Dim instance As New EntityListManager(Of T)(entityManager, filter, filterProperties)

Parameters

entityManager
EntityManager holding the Entities
filter
A predicate returning true if the tested entity belongs in the list
filterProperties
The watched properties. If supplied, changes to values in the watched properties trigger filtering. If null, any changes to Entities of this type will trigger filtering.
Remarks
The Filter uses a .NET Predicate<T>, a delegate that defines a set of criteria and determines whether the specified object passed to it meets those criteria. The Filter receives every addition, deletion or modification (based on the FilterProperties specified) of entities of the type watched, and determines whether the entity belongs in the list. If the Filter returns true the entity is added to or kept in the list; if the Filter returns false the entity is removed from the list. (Note that entities removed from the managed list are not removed from the EntityManager, nor are they deleted.)

Performance will be needlessly poor if the EntityListManager tests an entity every time any of its properties change. To avoid this, specify in the constructor or the FilterProperties property which entity properties are relevant to the filtering.

An EntityListManager holds weak references to the Lists it watches. This means that you will need to hold on to a reference to each ELM to insure that it does not go out of scope and get garbage collected. One approach to this is to use Lists that implement the IdeaBlade.Core.IHasListManager interface. This will insure each list keeps a reference to its ELM and any shared ELM's will not go out of scope until the last of their child lists do.

Example
// Example showing how a List<T> can be managed as a live list.
  public void EntityListManagerSample() {

  DomainModelEntityManager mgr = new DomainModelEntityManager();
  
  // Retrieve a customer and employee.
  var customer = mgr.Customers.FirstOrDefault(c => c.Id == 1);
  var employee = mgr.Employees.FirstOrDefault(e => e.Id == 1);

  // Load a List with customer's order summaries.
  var list = new List<OrderSummary>(customer.OrderSummaries);
  int orderCount = list.Count;

  // We want to watch for any new orders for this customer.
  // We can't "watch" the NavigationEntityProperty, so watch its FK. 
  var prop = OrderSummary.Customer_fk_IdEntityProperty;

  // Set up the manager.
  IListManager manager = new EntityListManager<OrderSummary>(mgr,
          os => os.Customer == customer,   // filter 
          new[] { prop },                  // watch
          list,                            // list to be managed
          false);                          // refresh now 

  // Create a new order - the list count should increment.
  OrderSummary aOrder = mgr.CreateEntity<OrderSummary>();
  aOrder.Employee = employee;
  aOrder.Customer = customer;
  aOrder.AddToManager();
 
  Assert.IsTrue(list.Count == orderCount + 1);

  // Now delete this order - the list count should decrement.
  aOrder.EntityAspect.Delete();
  Assert.IsTrue(list.Count == orderCount);
}

	
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

EntityListManager<T> Class
EntityListManager<T> Members
Overload List

Send Feedback